<?php $this->load->view('provider/template/_begin') ?>
<script src="//maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=<?php echo $this->setting_model->item('googlemap_api') ?>"
type="text/javascript"></script>
<script type="text/javascript">
  var map, marker;
  var default_lat = <?php echo isset($obj['lat']) ? $obj['lat'] : '37.4419' ?>;
  var default_lng = <?php echo isset($obj['lng']) ? $obj['lng'] : '-122.1419' ?>;
  
  function create_marker(point){
    marker = new GMarker(point, {draggable: false});
    GEvent.addListener(marker, "dragstart", function() {});
    GEvent.addListener(marker, "dragend", function() {
      var point = marker.getPoint();
      map.panTo(point);
      jQuery("#lat").val( point.lat().toFixed(5) );
      jQuery("#lng").val( point.lng().toFixed(5) );
    });
    map.addOverlay(marker);
  }
  function initialize() {
    if (GBrowserIsCompatible()) {
      map = new GMap2(document.getElementById("map"));
      map.addControl(new GMapTypeControl());
      map.addControl(new GScaleControl());
      map.enableScrollWheelZoom();
      var customUI = map.getDefaultUI();
      customUI.maptypes.hybrid = false;
      map.setUI(customUI);
      var center = new GLatLng( default_lat, default_lng );
      map.setCenter(center, 13);
      create_marker(center);
    }
  }
  jQuery(document).ready(function(){
    initialize();
  });  
</script>
<div class="form1">
  <table class="table1">
    <tr>
      <td class="text4">Title:</td>
      <td>
        <label><?php echo empty($obj["title"]) ? "" : $obj["title"] ?></label>
      </td>
      <td class="text4">Code:</td>
      <td><label><?php echo empty($obj["code"]) ? "" : $obj["code"] ?></label></td>
    </tr>
    <tr>
      <td class="text4">Categories:</td>
      <td>
        <label>
          <?php
          foreach ($obj["category"] as $category) {
            echo $this->category_model->to_string($category) . ', ';
          }
          ?>
        </label>
      </td> 
      <td class="text4">Related promotion:</td>
      <td>
        <label>
          <?php foreach ($obj["promotion2_id"] as $relate) { ?>
            <a href="<?php echo site_url('provider/promotion/show/' . $relate) ?>" style="padding-right: 10px">
              <?php echo $this->promotion_model->to_string($relate) ?>
            </a>
          <?php } ?>
        </label>
      </td>
    </tr>
    <tr>
      <td class="text4">Description:</td>
      <td colspan="3">
        <label><?php echo empty($obj["description"]) ? "" : $obj["description"] ?></label>
      </td>
    </tr>    
    <tr>
      <td class="text4">Start date:</td>
      <td><label><?php echo empty($obj["start_date"]) ? '' : date($this->setting_model->item('date_format'), $obj["start_date"]) ?></label></td>
      <td class="text4">Total promotion:</td>
      <td>
        <label><?php echo empty($obj["max_download"]) ? "" : $obj["max_download"] ?></label>
      </td>
    </tr>
    <tr>
      <td class="text4">Expire date:</td>
      <td><label><?php echo empty($obj["end_date"]) ? '' : date($this->setting_model->item('date_format'), $obj["end_date"]) ?></label></td>        
      <td class="text4">Limit per person:</td>
      <td><label><?php echo empty($obj["max_per_person"]) ? "" : $obj["max_per_person"] ?></label></td>
    </tr>
    <tr>
      <td class="text4">Country:</td>
      <td><label><?php echo $this->country_model->to_string($obj['country_id']) ?></label>
      </td>
      <td class="text4">Support channel:</td>
      <td>
        <?php
        $support_channel = array(
            PROMOTION_CHANNEL_ALL => $this->lang->line('label.promotion.support_channel.all'),
            PROMOTION_CHANNEL_EMAIL => $this->lang->line('label.promotion.support_channel.email'),
            PROMOTION_CHANNEL_SMS => $this->lang->line('label.promotion.support_channel.sms'));
        ?>
        <label><?php echo isset($support_channel[$obj['support_channel']]) ? $support_channel[$obj['support_channel']] : '' ?></label>
      </td>        
    </tr>
    <tr>
      <td class="text4">State:</td>
      <td><label><?php echo $this->state_model->to_string($obj['state_id']) ?></label>
      </td>
      <td class="text4">Support encode:</td>
      <td>
        <?php
        $support_encode = array(
            PROMOTION_ENCODE_ALL => $this->lang->line('label.promotion.support_encode.all'),
            PROMOTION_ENCODE_BARCODE => $this->lang->line('label.promotion.support_encode.barcode'),
            PROMOTION_ENCODE_TEXT => $this->lang->line('label.promotion.support_encode.text'));
        ?>
        <label><?php echo isset($support_encode[$obj['support_encode']]) ? $support_encode[$obj['support_encode']] : '' ?></label>
      </td>        
    </tr>
    <tr>
      <td class="text4">City:</td>
      <td>
        <label><?php echo $this->city_model->to_string($obj['city_id']) ?></label>
      </td>
    </tr>
    <tr>
      <td class="text4">Map:</td>
      <td colspan="3">
        <div id="map" class="input2" style="height: 200px"></div>
      </td>
    </tr>
    <tr>
      <td class="text4">Image(s):</td>
      <td colspan="3">
        <div style="float: left;width: 100%;padding-bottom: 5px;">
<?php foreach ($obj['images'] as $image) { ?>
            <img width="200px" style="padding: 5px"
                 src="<?php echo site_url('admin/' . 'promotion_media/preview/' . $image['id']) ?>" alt=""/>
<?php } ?>
        </div>
      </td>
    </tr>
    <tr>
      <td colspan="4">
        <div class="button">
          <div class="button_left"></div>
          <div class="button_bg">
            <a href="<?php echo site_url('provider/promotion/edit/' . $obj['id']) ?>">Edit promotion</a>
          </div>
          <div class="button_right"></div>
        </div>
        <div class="button">
          <div class="button_left"></div>
          <div class="button_bg">
            <a class="confirm" href="<?php echo site_url('provider/promotion/delete/' . $obj['id']) ?>">Delete promotion</a>
          </div>
          <div class="button_right"></div>
        </div>
      </td>
    </tr>
  </table>
</div>
<?php $this->load->view('provider/template/_end') ?>
